#!/usr/bin/perl

require "./mailadmin-lib.pl";
&ReadParse();

my ($err_msg, %dft_uinfo, $databytes, $passwd, $uquota, @badmailfrom);

$databytes = $in{'databytes'};
$uquota = $in{'uquota'};
$passwd = $in{'passwd'};
@badmailfrom = split ":", $in{'unamecache'};

unless ($databytes)
{
    $err_msg = $text{'msg_databytes_empty'};
    goto ERROR_OUT;
}

$err_msg = &check_input_num($databytes);
if ($err_msg)
{
    goto ERROR_OUT;
}

if ($databytes < 1)
{
    $databytes = 1;
}

$databytes = sprintf "%.0f", $databytes*1048756;


unless ($uquota)
{
    $err_msg = $text{'msg_uquota_empty'};
    goto ERROR_OUT;
}

$err_msg = &check_input_num($uquota);
if ($err_msg)
{
    goto ERROR_OUT;
}

if ($uquota < 1)
{
    $uquota = 1;
}

$uquota = sprintf "%.0f", $uquota*1048756;

unless ($passwd)
{
    $err_msg = $text{'msg_passwd_empty'};
    goto ERROR_OUT;
}

$dft_uinfo{'upasswd'} = $passwd;
$dft_uinfo{'uquota'} = $uquota;


#$err_msg = &delete_domain($dname);

&save_badmailfrom(\@badmailfrom);

&save_dftuinfo(\%dft_uinfo);

&save_databytes($databytes);

&serv_act("popserv", "stop");
&serv_act("smtpserv", "stop");
&serv_act("mailserv", "restart");
&serv_act("smtpserv", "start");
&serv_act("popserv", "start");

if ($err_msg)
{
    goto ERROR_OUT;
}

&redirect("");

exit 0;

ERROR_OUT:;

my (@headp, @footp);
@headp = ($text{'error'}, "");
@footp = ("serv_conf.cgi?servradio=mailserv", $text{'back_mailsrvconf'});
&mail_error(\@headp, \@footp, $text{'err_title_save_mailserv_conf'}, $err_msg);
